package com.macaline.util;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.seg.Segment;
import com.hankcs.hanlp.seg.common.Term;
import com.hankcs.hanlp.tokenizer.NLPTokenizer;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class HanlpUtil {


    public static void segment(String text){
        Segment segment = HanLP.newSegment();
        List<Term> seg = NLPTokenizer.segment(text);
        for(Term term : seg){
            System.out.println(term.word);
        }
        List<String> list = new ArrayList<String>();
        NLPTokenizer.segment(text).forEach(term -> {
            if (StringUtils.isNotBlank(term.word)) {
                list.add(term.word);
            }
        });
        System.out.println(list);
    }

    public static void main(String[] args) {
        segment("中国科学院计算技术研究所的宗成庆教授正在教授自然语言处理课程");
    }

}
